/*
* @Author: z.p
* @Project: Zdotp
* @Date: 2025年01月15日
* @Description: kcpActorHandler处理类
*/

using Pb;
using Zdotp.Actor;
using Zdotp.Actor.Controller;
using Zdotp.Actor.Kcp;
using Zdotp.Actor.Packet;
using Zdotp.Net.NetMessageHandler;

namespace TimerServer.Actors;

public class KcpHandler : KcpMessageHandler<DataPacket>
{
    protected override void Run(ActorKcp kcpActor, ActorSystem system, uint sessionId, DataPacket netMessage)
    {
        kcpActor.Logger.Info($"收到客户端消息, sessionId : {sessionId}");
        var str = netMessage.Content;
        
        // 如果没有这个actor, 就hash到一个特定的actor中
        const int receiveActorId = 288;
        kcpActor.SendMessage<TestMessage>(message =>
        {
            message.Data = str;
        }, receiveActorId, sessionId);
        // gate类内部使用SendMsgToClient回显给客户端
        kcpActor.SendMsgToClient(sessionId, netMessage);
    }
}

public class TimerKcpConnectHandler : ActorController<ActorKcp, ConnectMessage>
{
    protected override void Run(ActorKcp actor, ActorSystem system, MessageInfo info, ConnectMessage data)
    {
        actor.Logger.Info($"session {info.SessionId} connect...");
    }
}

public class TimerKcpDisconnectHandler : ActorController<ActorKcp, DisConnectMessage>
{
    protected override void Run(ActorKcp actor, ActorSystem system, MessageInfo info, DisConnectMessage data)
    {
        actor.Logger.Info($"session {info.SessionId} disconnect...");
    }
}